package my.soft.aiteacher.teacher.mapStruct;

import com.alibaba.fastjson.JSONObject;
import my.soft.aiteacher.teacher.pojo.KeypointItemDO;
import my.soft.aiteacher.teacher.pojo.KeypointItemVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.HashMap;
import java.util.Map;

@Mapper(componentModel = "spring")
public interface KeyPointItemMapstruct {
    KeypointItemDO toQuestionnaireItemDO(KeypointItemVO questionnaireVO);
    @Mapping(target = "options", source = "options", qualifiedByName = "jsonObjectToMap")
    KeypointItemVO toQuestionnaireItemVO(KeypointItemDO questionnaireDO);
    @Named("jsonObjectToMap")
    default Map<String, String> jsonObjectToMap(JSONObject jsonObject) {
        if (jsonObject == null) {
            return new HashMap<>();
        }
        Map<String, String> map = new HashMap<>();
        for (String key : jsonObject.keySet()) {
            map.put(key, jsonObject.getString(key));
        }
        return map;
    }
}
